local json = require("ac.json")
local sync = require("ac.acctl_sync")
local resip = require("ac.acctl_resip")
local web = require("ac.acctl_web")
local sys = require("ac.acctl_sys")

aparr={}

function ap_reg(ap, apnetstatus)
	mackey = ap.macstr
	if aparr[mackey] == nil then
		aparr[mackey] = {adopt=false}
	end
	aparr[mackey].ap = ap
	aparr[mackey].status = json.decode(apnetstatus)
	apparr[mackey].adopt = web.web_adopt(apnetstatus)
	print("LUA: status:" .. apnetstatus)
	return aparr[mackey].adopt
end

function ap_sync(macstr, jsonstatus)
	local s = json.decode(jsonstatus)
	aparr[macstr].status = web.web_sync(jsonstatus);
	local d = aparr[macstr].status
	if d == nil then
		aparr[macstr].status = 
		{network={}, wireless={}, switch={}, vlan={}}
	end
	return sync.statussync(s, d)
end

function ap_allocip(macstr)
	local s, d = resip.resip_alloc(macstr)
	if s == nil then
		return 0, ""
	end
	return sync.netsync(s,d)
end

-- get resip
local ipoolstr = web.web_resip()
resip.resip_init(json.decode(ipoolstr))
-- get ac uuid
acuuid = sys.acuuid()
